﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using AdmLaboratorios.Business;
using AdmLaboratorios.DTO;

namespace AdmLaboratorios
{
    public partial class frmValeConsulta : Form
    {
        public frmValeConsulta()
        {
            InitializeComponent();
        }

        private void btnCerrar_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void frmValeConsulta_Load(object sender, EventArgs e)
        {
            cbTipo.Items.Clear();
            cbTipo.Items.Add(eValeTipo.CONSUMO.ToString());
            cbTipo.Items.Add(eValeTipo.DEVOLUCION.ToString());
            cbTipo.SelectedIndex = 0;
        }

        private void cbEstado_SelectedIndexChanged(object sender, EventArgs e)
        {
            ReloadGrid();
        }

        internal void ReloadGrid()
        {
            gv.DataSource = null;
            gv.DataSource = Stock.ConsultaValtes(cbTipo.Text.Trim().ToUpper());
            lblRegistros.Text = ((DataTable)gv.DataSource).Rows.Count.ToString();
        }

        private void btConsultar_Click(object sender, EventArgs e)
        {
            Consultar();
        }

        private void Consultar()
        {
            if (gv.SelectedRows.Count == 1)
            {
                if ((string)gv.SelectedRows[0].Cells["Tipo"].Value == eValeTipo.CONSUMO.ToString())
                {
                    var f = FormsFactory.ShowForm<frmValeConsumo>();
                    f.SetValues((int)gv.SelectedRows[0].Cells["Id"].Value);
                }
                else
                {
                    var f = FormsFactory.ShowForm<frmValeDevolucion>();
                    f.SetValues((int)gv.SelectedRows[0].Cells["Id"].Value);
                }
            }
        }

        private void gv_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            Consultar();
        }
    }
}
